package org.example.listener;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.example.core.SpringContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 流程结束时间：更新流程状态为结束(通过)
 *
 * @author wanghuidong
 * 时间： 2024/6/28 10:44
 */
public class FlowEndListener implements ExecutionListener {

    private Logger logger = LoggerFactory.getLogger(ExecutionListener.class);

    @Override
    public void notify(DelegateExecution execution) {
        System.out.println("flow end");

        //清理掉变量，否则运行时相关表的清理会发生异常
        execution.getTransientVariables().forEach((k, v) -> {
            execution.removeTransientVariable(k);
        });

        RuntimeService runtimeService = SpringContext.getBean(RuntimeService.class);
        System.out.println(runtimeService);


    }
}
